// 导入需要使用的Java类库
package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
// 导入Spring Security权限控制注解
import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
// 导入Spring依赖注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring Web MVC注解
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 导入项目自定义注解和类
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目Controller
 * 
 * @author ruoyi
 * @date 2025-09-03
 */
@Api(tags = "护理项目管理")
// 标记为RESTful风格的控制器
@RestController
// 设置统一的请求路径前缀
@RequestMapping("/nursing/project")
public class NursingProjectController extends BaseController
{
    // 自动注入护理项目服务接口
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @ApiOperation("查询护理项目列表")
    // 权限控制注解，检查用户是否有'nursing:project:list'权限
    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    // 处理GET请求，路径为/list
    @GetMapping("/list")
    public TableDataInfo<List<NursingProject>> list(NursingProject nursingProject)
    {
        // 初始化分页参数
        startPage();
        // 调用服务层方法查询护理项目列表
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        // 返回带分页信息的数据表格结果
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @ApiOperation("导出护理项目列表")
    // 权限控制注解，检查用户是否有'nursing:project:export'权限
    @PreAuthorize("@ss.hasPermi('nursing:project:export')")
    // 日志记录注解，标记操作类型为导出
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    // 处理POST请求，路径为/export
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingProject nursingProject)
    {
        // 查询需要导出的数据列表
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        // 创建Excel工具类实例，指定处理的实体类为NursingProject
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        // 导出Excel文件
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @ApiOperation(value = "获取护理项目详细信息",notes = "根据ID获取护理项目详细信息")
    // 权限控制注解，检查用户是否有'nursing:project:query'权限
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    // 处理GET请求，路径包含路径变量id
    @GetMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "护理项目ID", required = true, dataType = "Long", paramType = "path")
    public R<NursingProject> getInfo(@ApiParam("护理项目ID") @PathVariable("id") Long id)
    {
        // 调用服务层方法根据ID查询护理项目信息，并返回成功结果
        return R.ok(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @ApiOperation("新增护理项目")
    // 权限控制注解，检查用户是否有'nursing:project:add'权限
    @PreAuthorize("@ss.hasPermi('nursing:project:add')")
    // 日志记录注解，标记操作类型为新增
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    // 处理POST请求，路径为根路径
    @PostMapping
    public AjaxResult add(@ApiParam("护理项目对象") @RequestBody NursingProject nursingProject)
    {
        // 调用服务层方法新增护理项目，并返回操作结果
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @ApiOperation("修改护理项目")
    // 权限控制注解，检查用户是否有'nursing:project:edit'权限
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')")
    // 日志记录注解，标记操作类型为修改
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    // 处理PUT请求，路径为根路径
    @PutMapping
    public AjaxResult edit(@ApiParam("护理项目对象") @RequestBody NursingProject nursingProject)
    {
        // 调用服务层方法修改护理项目，并返回操作结果
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @ApiOperation("删除护理项目")
    // 权限控制注解，检查用户是否有'nursing:project:remove'权限
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')")
    // 日志记录注解，标记操作类型为删除
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    // 处理DELETE请求，路径包含路径变量ids
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("护理项目ID数组") @PathVariable Long[] ids)
    {
        // 调用服务层方法批量删除护理项目，并返回操作结果
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }
}
